package com.etone.autotesting.listener;

import java.util.LinkedHashMap;
import java.util.Map;

import javassist.bytecode.annotation.Annotation;

import com.impetus.annovention.listener.ClassAnnotationDiscoveryListener;

public class WebServiceClassAnnotationListener implements ClassAnnotationDiscoveryListener {

	private Map<String, Class> classMap;

	public WebServiceClassAnnotationListener() {
		classMap = new LinkedHashMap<String, Class>();
	}

	/**
	 * 
	 * @return
	 */
	public Map<String, Class> getClassMap() {
		return classMap;
	}

	/**
	 * 发现类上的注解
	 * 
	 * @param clazz
	 * @param annotation
	 * @param source
	 */
	@Override
	public void discovered(String clazz, String annotation, Annotation source) {
		Class<?> classObject;
		try {
			classObject = Class.forName(clazz);
			if (classObject.isInterface()) {
				String key = classObject.getSimpleName().toLowerCase();
				if (!classMap.containsKey(key))
					classMap.put(key, classObject);
			}
		} catch (ClassNotFoundException ex) {
			System.out.println(clazz + " | " + ex.getMessage());
		}
	}

	@Override
	public String[] supportedAnnotations() {
		// Listens for @ClassResource annotations.
		return new String[] { "javax.jws.WebService" };
	}
}
